{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Find Three Consecutive Integers That Sum to a Given Number"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Medium"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #math #simulation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数学 #模拟"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: sumOfThree"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #找到和为给定整数的三个连续整数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个整数&nbsp;<code>num</code>&nbsp;，请你返回三个连续的整数，它们的&nbsp;<strong>和</strong>&nbsp;为<em>&nbsp;</em><code>num</code>&nbsp;。如果&nbsp;<code>num</code>&nbsp;无法被表示成三个连续整数的和，请你返回一个 <strong>空</strong>&nbsp;数组。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>num = 33\n",
    "<b>输出：</b>[10,11,12]\n",
    "<b>解释：</b>33 可以表示为 10 + 11 + 12 = 33 。\n",
    "10, 11, 12 是 3 个连续整数，所以返回 [10, 11, 12] 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>num = 4\n",
    "<b>输出：</b>[]\n",
    "<b>解释：</b>没有办法将 4 表示成 3 个连续整数的和。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>0 &lt;= num &lt;= 10<sup>15</sup></code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [find-three-consecutive-integers-that-sum-to-a-given-number](https://leetcode.cn/problems/find-three-consecutive-integers-that-sum-to-a-given-number/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [find-three-consecutive-integers-that-sum-to-a-given-number](https://leetcode.cn/problems/find-three-consecutive-integers-that-sum-to-a-given-number/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['33', '4']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num %3 !=0:\n",
    "            return []\n",
    "        pose = num//3\n",
    "        return [pose-1,pose,pose+1]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        # 以前做过的同类题目，暴力时间复杂度是n3，但题目要求时间复杂度是n2，\n",
    "        # 因此以前那道题是最外圈一个for，内圈一个双指针。\n",
    "        if num % 3 != 0:\n",
    "            return []\n",
    "        else:\n",
    "            return [num // 3 - 1, num // 3, num // 3 + 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num % 3 == 0:\n",
    "            mid = num // 3\n",
    "            return [mid-1,mid,mid+1]\n",
    "        else:\n",
    "            return []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num%3!=0:\n",
    "            return []\n",
    "        else:\n",
    "            return [num//3-1,num//3,num//3+1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        pose = num//3\n",
    "        if pose-1+pose+pose+1 == num:\n",
    "            return [pose-1,pose,pose+1]\n",
    "        return []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num%3 == 0:\n",
    "            return [num//3-1, num//3, num//3+1]\n",
    "        else:\n",
    "            return []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        pose = num//3\n",
    "        if pose-1+pose+pose+1 == num:\n",
    "            return [pose-1,pose,pose+1]\n",
    "        return []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        div, mod = divmod(num, 3)\n",
    "        if mod != 0:\n",
    "            return []\n",
    "        \n",
    "        return [div - 1, div, div + 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num % 3 != 0:\n",
    "            return []\n",
    "        return [num//3-1, num//3, num//3+1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        return [num // 3 - 1,num // 3,num // 3 + 1] if num % 3 == 0 else []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num%3!=0:\n",
    "            return []\n",
    "        else:\n",
    "            return [num//3-1,num//3,num//3+1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        return [num//3-1,num//3,num//3+1] if num%3==0 else []\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num % 3:\n",
    "            return []\n",
    "        return [num // 3 - 1, num // 3, num // 3 + 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        return [] if num%3 != 0 else [num//3 -1, num//3, num//3+1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num % 3 == 0:\n",
    "            n = num // 3\n",
    "            return [n-1, n, n+1]\n",
    "        return []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        pose = num//3\n",
    "        if pose-1+pose+pose+1 == num:\n",
    "            return [pose-1,pose,pose+1]\n",
    "        return []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num % 3 != 0:\n",
    "            return []\n",
    "        v = num // 3\n",
    "        return [v - 1, v, v + 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num % 3 != 0: return []\n",
    "        return [num//3-1, num//3, num//3+1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num%3==0:\n",
    "            center = num//3\n",
    "            left = center-1\n",
    "            right = center +1\n",
    "            return [left,center,right]\n",
    "        return []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        # 检查 num 是否能表示为三个连续整数的和\n",
    "        if (num - 3) % 3 != 0:\n",
    "            return []\n",
    "        \n",
    "        x = (num - 3) // 3\n",
    "        return [x, x + 1, x + 2]\n",
    "\n",
    "# 示例\n",
    "sol = Solution()\n",
    "print(sol.sumOfThree(6))  # 输出 [1, 2, 3]\n",
    "print(sol.sumOfThree(9))  # 输出 [2, 3, 4]\n",
    "print(sol.sumOfThree(1))  # 输出 []\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num%3 == 0:\n",
    "            n = num//3\n",
    "            return [n-1, n, n+1]\n",
    "        else:\n",
    "            return []\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num %3 !=0: return []\n",
    "        a=num//3\n",
    "        return [a-1,a,a+1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num % 3 != 0:\n",
    "            return []\n",
    "        t = num // 3\n",
    "        return [t - 1, t, t + 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num % 3 != 0:\n",
    "            return []\n",
    "        mid = num // 3\n",
    "        return [mid-1,mid,mid+1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "\n",
    "        return [] if num%3!=0 else  [num//3-1,num//3,num//3+1]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        # 通过该题目要求我们发现只有当num是3的倍数才有这样的数组存在\n",
    "        if num % 3 == 0:\n",
    "            return [num // 3 - 1, num // 3, num // 3 + 1]\n",
    "        return []\n",
    "        \n",
    "        '''\n",
    "        left = 0\n",
    "        right = num\n",
    "        while left <= right:\n",
    "            mid = (left + right) >> 1\n",
    "            if 3 * mid == num:\n",
    "                return [mid - 1, mid, mid + 1]\n",
    "            elif 3 * mid > num:\n",
    "                right = mid - 1\n",
    "            else:\n",
    "                left = mid + 1\n",
    "        return []\n",
    "        '''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num % 3 == 0:\n",
    "            return [num // 3 - 1, num // 3, num // 3 + 1]\n",
    "        return []\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "      if num % 3:\n",
    "        return []\n",
    "      return [num // 3 - 1, num // 3, num // 3 + 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num % 3 == 0:\n",
    "            return [num // 3 - 1, num // 3, num // 3 + 1]\n",
    "        return []\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num % 3:\n",
    "            return []\n",
    "        else:\n",
    "            b = num // 3\n",
    "            a, c = b-1, b+1\n",
    "            return [a, b, c]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num%3!=0:\n",
    "            return []\n",
    "        else:\n",
    "            mid = num//3\n",
    "            return [mid-1, mid, mid+1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        a = int(num/3) -1 \n",
    "        b = int(num/3)\n",
    "        c = int(num/3)+1\n",
    "        if a+b+c == num:\n",
    "            return [a,b,c]\n",
    "        else:\n",
    "            return []\n",
    "\n",
    "\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        s = num\n",
    "        if s % 3:\n",
    "            return []\n",
    "        return [s//3-1, s//3, s//3+1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num%3 !=0:\n",
    "            return []\n",
    "        a=num//3\n",
    "        return [a-1,a,a+1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        # 检查 num 是否能表示为三个连续整数的和\n",
    "        if (num - 3) % 3 != 0:\n",
    "            return []\n",
    "        \n",
    "        x = (num - 3) // 3\n",
    "        return [x, x + 1, x + 2]\n",
    "\n",
    "# 示例\n",
    "sol = Solution()\n",
    "print(sol.sumOfThree(6))  # 输出 [1, 2, 3]\n",
    "print(sol.sumOfThree(9))  # 输出 [2, 3, 4]\n",
    "print(sol.sumOfThree(1))  # 输出 []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num%3:\n",
    "            return []\n",
    "        x = num//3\n",
    "        return [x-1,x,x+1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num % 3 == 0:\n",
    "            return [num // 3 - 1, num // 3, num // 3 + 1]\n",
    "        else:\n",
    "            return []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        left = 0\n",
    "        right = num\n",
    "        while left <= right:\n",
    "            mid = (left + right) >> 1\n",
    "            if 3 * mid == num:\n",
    "                return [mid-1, mid, mid+1]\n",
    "            elif 3 * mid > num:\n",
    "                right = mid - 1\n",
    "            else:\n",
    "                left = mid + 1\n",
    "        return []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        # 检查 num 是否能表示为三个连续整数的和\n",
    "        if (num - 3) % 3 != 0:\n",
    "            return []\n",
    "        \n",
    "        x = (num - 3) // 3\n",
    "        return [x, x + 1, x + 2]\n",
    "\n",
    "# 示例\n",
    "sol = Solution()\n",
    "print(sol.sumOfThree(6))  # 输出 [1, 2, 3]\n",
    "print(sol.sumOfThree(9))  # 输出 [2, 3, 4]\n",
    "print(sol.sumOfThree(1))  # 输出 []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num % 3:return []\n",
    "        return [num//3-1,num//3,num//3+1]\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        res = []\n",
    "        if num % 3 == 0:\n",
    "            n = num // 3\n",
    "            res += [n-1, n, n+1]\n",
    "\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num % 3 == 0:\n",
    "            return [num // 3 - 1, num // 3, num // 3 + 1]\n",
    "        return []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        return [] if num%3!=0 else  [num//3-1,num//3,num//3+1]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num % 3 != 0:\n",
    "            return []\n",
    "        x = num//3\n",
    "        return [x-1, x, x+1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        res=[]\n",
    "        def check(x:int)->bool:\n",
    "            return x+x+1+x+2>=num\n",
    "        l,r=-10**15,10**15\n",
    "        while l<r:\n",
    "            mid=(l+r)>>1\n",
    "            if check(mid):r=mid\n",
    "            else:l=mid+1\n",
    "        if l+l+1+l+2==num:\n",
    "            res=[l,l+1,l+2]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    # * 数学\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        if num % 3 == 0:\n",
    "            return [num // 3 - 1, num // 3, num // 3 + 1]\n",
    "\n",
    "        return []\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sumOfThree(self, num: int) -> List[int]:\n",
    "        # n-1 n n+1 => 3n\n",
    "        res = []\n",
    "        if num % 3 > 0:\n",
    "            return res\n",
    "        mid = num // 3\n",
    "        return [mid-1, mid, mid+1] "
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
